package com.kkd.kkdapp.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.MyBaseAdapter;
import com.kkd.kkdapp.http.entity.BankMessage;
import com.nostra13.universalimageloader.core.ImageLoader;

public class MyBlockAdapter extends MyBaseAdapter<BankMessage> {

	private boolean flag = false;

	public MyBlockAdapter(Context context) {
		super(context);

	}

	@Override
	public View getMyView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewhodler;
		if (convertView == null) {
			viewhodler = new ViewHodler();
			convertView = View.inflate(context, R.layout.myblock_listview_item,
					null);
			// 银行图标
			viewhodler.bank_icon = (ImageView) convertView
					.findViewById(R.id.bank_icon);
			// 银行卡名字
			viewhodler.block_name = (TextView) convertView
					.findViewById(R.id.block_name);
			// 银行卡号
			viewhodler.card_number = (TextView) convertView
					.findViewById(R.id.card_number);
			viewhodler.card_numbertv = (TextView) convertView
					.findViewById(R.id.card_numbertv);
			viewhodler.block_top = (RelativeLayout) convertView
					.findViewById(R.id.block_top);
			viewhodler.hint_tv = (TextView) convertView
					.findViewById(R.id.hint_tv);
			convertView.setTag(viewhodler);
		} else {
			viewhodler = (ViewHodler) convertView.getTag();
		}
		List<BankMessage> mList = getAdapterData();
		if ("农业银行".equals(mList.get(position).getBankName())) {
			viewhodler.block_top
					.setBackgroundResource(R.drawable.bank_agriculture);
		} else if ("建设银行".equals(mList.get(position).getBankName())) {
			viewhodler.block_top
					.setBackgroundResource(R.drawable.bank_business);
		} else if ("浙商银行".equals(mList.get(position).getBankName())) {
			viewhodler.block_top
					.setBackgroundResource(R.drawable.bank_construction);
		} else if ("招商银行".equals(mList.get(position).getBankName())) {
			viewhodler.block_top
					.setBackgroundResource(R.drawable.bankcard_bg_cmb);
		}
//		ImageCache.getInstance(context)
//				.displayImage(viewhodler.bank_icon,
//						mList.get(position).getAppImageUrl(),
//						R.drawable.mybank_default);
		ImageLoader.getInstance().displayImage(mList.get(position).getAppImageUrl(), viewhodler.bank_icon);
		viewhodler.block_name.setTag(position);
		viewhodler.block_name.setText(mList.get(position).getBankName());
		viewhodler.card_number.setTag(position);
		viewhodler.card_numbertv.setText("**** **** **** ");
		viewhodler.card_number.setText(mList.get(position).getCardNo()
				.substring(mList.get(position).getCardNo().length() - 4));
		viewhodler.hint_tv.setTag(position);
		String limit = mList.get(position).getLimit();
		String[] limits = limit.split("@");
		String[] quota = limits[0].split("/");
		viewhodler.hint_tv.setText("*本卡充值限额：单笔最多" + quota[0] + "元/每日最多"
				+ quota[1] + "元");
		return convertView;
	}

	static class ViewHodler {
		CheckBox bank_cb;
		ImageView bank_icon;
		TextView block_name;
		TextView card_number;
		RelativeLayout block_top;
		TextView card_numbertv;
		TextView hint_tv;
	}

}
